﻿namespace Common
{
    /// <summary>
    /// 游戏进程
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Process<T> : ILife where T : new()
    {
        #region 单例

        private static T? _instance;
        public static T Instance
        {
            get
            {
                if (_instance == null) 
                    _instance = new T();

                return _instance;
            }
        }

        #endregion

        public int ProcessID { get; set; }
        readonly List<ILife> lifes = new();

        public void Awake()
        {
            foreach (ILife life in lifes)
            {
                life.Awake();
            }
        }

        public void Tick()
        {
            foreach (ILife life in lifes)
            {
                life.Tick();
            }
        }

        public void Destroy()
        {
            foreach (ILife life in lifes)
            {
                life.Destroy();
            }
        }

        protected void AddLife(ILife life)
        {
            lifes.Add(life);
        }

        public abstract void HandleConsoleCommand(ConsoleCommand cmd, string? arg);
    }
}